package com.suneast.suneaststore.modules.personal.order.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.personal.order.ListBean;
import com.suneast.suneaststore.ui.customview.RoundImageView;

public class StandardGoodsAdapter extends BaseAdapter<StandardGoodsAdapter.ViewHolder, ListBean.GoodsBean> {
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_standard_order_goods, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ListBean.GoodsBean goods = list.get(position);

        Glide.with(holder.ivGoods.getContext()).load(goods.getThumb()).into(holder.ivGoods);
        holder.tvGoodsName.setText(goods.getTitle());
        holder.tvGoodsContent.setText(holder.tvGoodsContent.getContext().getString(R.string.goods_content,
                goods.getGoodssn(), goods.getOptionname()));
        holder.tvGoodsPrice.setText(holder.tvGoodsContent.getContext().getString(R.string.goods_price, goods.getPrice()));
        holder.tvGoodsAmount.setText(holder.tvGoodsContent.getContext().getString(R.string.goods_amount, goods.getTotal()));
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private RoundImageView ivGoods;
        private TextView tvGoodsName;
        private TextView tvGoodsContent;
        private TextView tvGoodsPrice;
        private TextView tvGoodsAmount;

        ViewHolder(View itemView) {
            super(itemView);
            ivGoods = itemView.findViewById(R.id.cv_goods);
            tvGoodsName = itemView.findViewById(R.id.tv_goods_name);
            tvGoodsContent = itemView.findViewById(R.id.tv_goods_content);
            tvGoodsPrice = itemView.findViewById(R.id.tv_goods_price);
            tvGoodsAmount = itemView.findViewById(R.id.tv_goods_amount);
        }
    }
}
